<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <ul id="city">
      <li><a href="1.html">data1</a></li>
      <li><a href="2.html">data2</a></li>
      <li><a href="3.html">data3</a></li>
    </ul>
    <button onclick="appendLiChild()">添加子元素</button>
    <script>
      //注意：方法命名 系统 API 冲突问题？
      function appendLiChild() {
        var aComp = document.createElement('a')
        aComp.textContent = 'data4'
        aComp.setAttribute('href', '4.html')
        var liComp = document.createElement('li')

        liComp.appendChild(aComp)
        //获得 父元素
        var ulComp = document.getElementById('city')
        //尾部添加
        ulComp.appendChild(liComp)
      }
    </script>
  </body>
</html>
